<?php
class Longadmin_OrderController extends Zend_Controller_Action
{
	
	public function updateAction()
	{
		
	}	
  
	public function deleteAction()
	{
		$id = $_GET['id'];
		$model = new Model_Order();
		//$modelOrderDetail = new Model_Orderdetail();
		//$modelOrderDetail->deleteODetailByOrderId($id);
		$model->deleteOrderById($id);
	}	

	public function listAction()
	{
		$rp = $_POST['rp'];
		$page = $_POST['page'];
		$pageStart = ($page-1)*$rp;
		$orderModel = new Model_Order();
		$totalarray = $orderModel->getOrderAll();
		$result= $orderModel->getOrderLimit($rp,$pageStart);
		$test = array();
		$i=0;
		
		foreach($result as $x)
		{
			$test[$i]['o_id'] = "".$x['o_id']."";
			$modelUser = new Model_User();
			$user = $modelUser->getUserByID($x['u_id']);
			$test[$i]['u_id'] = "".$user[0]['u_hoten']."";
			
			$modelPay = new Model_Payment();
			$pay = $modelPay->getPaymentById($x['pay_id']);
			$test[$i]['pay_id'] = "".$pay[0]['pay_loai']."";
			
			$modelShip= new Model_Shipper();
			$ship = $modelShip->getShipperById($x['ship_id']);
			$test[$i]['ship_id'] = "".$ship[0]['ship_ten']."";			
			
			$test[$i]['o_ngaydat'] = "".$x['o_ngaydat']."";
			
			$modelOrderstatus= new Model_Orderstatus();
			$orderstatus = $modelOrderstatus->getOSByID($x['os_id']);
			$test[$i]['os_id'] = "".$orderstatus[0]['os_ten']."";
			
			$modelPaymentstatus= new Model_Paymentstatus();
			$paymentstatus = $modelPaymentstatus->getPSByID($x['ps_id']);
			$test[$i]['ps_id'] = "".$paymentstatus[0]['ps_ten']."";
			$i++;
		}

		$data = array();
		$data['page'] = $page;
		$data['total'] = count($totalarray);
		foreach ($test as $x) {
			$data['rows'][] = array(
			'id' => $x['o_id'],
			'cell' => array($x['o_id'],$x['u_id'], $x['ship_id'],$x['pay_id'],$x['o_ngaydat'], $x['os_id'],$x['ps_id']));
		}
		
		$this->_helper->viewRenderer->setNoRender();
		echo json_encode($data);	
	}
	
}